﻿using SlaughterItem.Common.Domains.Warehouse;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static WinFormsApp1.TongShiWei.COA.LivestockData;

namespace WinFormsApp1.TongShiWei.COA
{
    public partial class ProductionData : UIForm
    {
        public ProductionData()
        {
            InitializeComponent();
            ShowLivestockData();
        }
        public delegate void GetProductionId(int ProductionId,string ProductionName);
        public event GetProductionId onGetProductionId;
        #region 生产入库
        public void ShowLivestockData()
        {
            List<Production> ProductionList = new List<Production>()
            {
                new Production{ProductionId=1,ProductionTime=DateTime.Parse("2023-7-10"),StorageType="白条入库",StorageData="白条仓库",UPCName="带皮白条",StorageJNum=10,StorageNum=50,CreateNum="KG123",CreateTime=DateTime.Parse("2023-8-10"),CreateClass="Cr123"},
                new Production{ProductionId=2,ProductionTime=DateTime.Parse("2023-7-11"),StorageType="分割入库",StorageData="分割仓库",UPCName="去蹄带皮白条",StorageJNum=8,StorageNum=40,CreateNum="KG133",CreateTime=DateTime.Parse("2023-8-11"),CreateClass="Cr133"},
                new Production{ProductionId=3,ProductionTime=DateTime.Parse("2023-7-12"),StorageType="副产入库",StorageData="副产仓库",UPCName="带蹄带皮",StorageJNum=3,StorageNum=15,CreateNum="KG155",CreateTime=DateTime.Parse("2023-8-15"),CreateClass="Cr199"},
            };
            foreach (Production item in ProductionList)
            {
                this.dataGridView1.Rows.Add(false, item.ProductionId, item.ProductionTime.ToString(), item.StorageType, item.StorageData, item.UPCName, item.StorageJNum, item.StorageNum, item.CreateNum, item.CreateTime, item.CreateClass);
            }
        }
        public class Production
        {
            //生产入库ID
            public int ProductionId { get; set; }
            //单据日期
            public DateTime ProductionTime { get; set; }
            //入库类型
            public string StorageType { get; set; }
            //入库仓库
            public string StorageData { get; set; }
            //商品代号
            public string UPCName { get; set; }
            //入库件数
            public int StorageJNum { get; set; }
            //入库数量
            public int StorageNum { get; set; }
            //生产批号
            public string CreateNum { get; set; }
            //生产日期
            public DateTime CreateTime { get; set; }
            //生产班组
            public string CreateClass { get; set; }
        }
        #endregion

        private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex > 0)
            {
                return;
            }
            else
            {
                this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = true ? false : true;
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Index != e.RowIndex)
                    {
                        this.dataGridView1.Rows[row.Index].Cells[0].Value = false;
                    }
                }
            }
        }
        //选择
        private void uiButton1_Click_1(object sender, EventArgs e)
        {
            int GetNum = 0;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if ((bool)this.dataGridView1.Rows[row.Index].Cells[0].Value == true)
                {
                    GetNum++;
                    int ProductionId = Convert.ToInt32(this.dataGridView1.Rows[row.Index].Cells[1].Value);
                    string ProductionName = this.dataGridView1.Rows[row.Index].Cells[5].Value.ToString();
                    onGetProductionId?.Invoke(ProductionId, ProductionName);
                    this.Close();
                }
            }
            if (GetNum == 0)
            {
                MessageBox.Show("还没有选择商品");
            }
        }
    }
}
